<?php
/**
 * Created by PhpStorm.
 * User: peter
 * Date: 2018/6/20
 * Time: 下午7:14
 */

namespace app\mall\controller;


use think\Request;

class Address extends Auth
{
    /**
     * @purpose 创建收货地址
     * @param Request $request
     * @return array
     */
    public function add (Request $request)
    {
        $data  = $request->post();
        return \app\mall\logic\Address::create($data, self::$user_info['uid']);
    }

    /**
     * @purpose 编辑收货地址
     * @param Request $request
     * @return array
     */
    public function edit (Request $request)
    {
        $data   = $request->post();
        return \app\mall\logic\Address::update($data, self::$user_info['uid']);
    }

    /**
     * @purpose 通过ID获取地址信息
     * @param Request $request
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function info (Request $request)
    {
        $id     = $request->get('id',0);
        return  \app\mall\logic\Address::info($id, self::$uid);
    }

    /**
     * @purpose 获取收货地址列表
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function items ()
    {
        return \app\mall\logic\Address::items(self::$user_info['uid']);
    }

    /**
     * @purpose 设为默认
     * @param Request $request
     * @return array
     * @throws \think\exception\PDOException
     */
    public function setDefault (Request $request)
    {
        $id     = $request->post('id');
        return \app\mall\logic\Address::setDefault($id, self::$user_info['uid']);
    }

    /**
     * @purpose 删除地址
     * @param Request $request
     * @return array
     */
    public function delete (Request $request)
    {
        $ids    = $request->post();
        return \app\mall\logic\Address::delete($ids, self::$user_info['uid']);
    }
}